<?php
namespace UserForm\Form;
use Zend\Form\Form;
class RegisterForm extends Form
{
    public function __construct($name = null)
    {
        parent::__construct('Register');
        $this->setAttribute('method','post');
        $this->setAttribute('enctype','multipart/form-data');

        $this->add(array( 'name'=>'name', 'attributes'=>array( 'type'=>'Text', ), 'options'=>array( 'label'=>'name', ), ));


        // 性别单选框
        $this->add(array(
            'type' => 'Radio',
            'name' =>'sex',
            'options' => array(
                'label' => 'Sex',
                'value_options' => array(
                    'male' => 'male',
                    'female' => 'female'
                )
            )
        ));

        // 学历下拉框
        $this->add(array(
            'type' => 'Select',
            'name' => 'education',
            'options' => array(
                'label' => 'Education',
                'value_options' => array(
                    'High School' => 'High School',
                    'Bachelor' => 'Bachelor',
                    'Master' => 'Master',
                    'PhD' => 'PhD'
                )
            )
        ));
        $this->add(array( 'name'=>'contact', 'attributes'=>array( 'type'=>'Text', ), 'options'=>array( 'label'=>'contact', ), ));
        $this->add(array( 'name'=>'homepage', 'attributes'=>array( 'type'=>'Text', ), 'options'=>array( 'label'=>'homepage', ), ));
        // 个人爱好多选框
        $this->add(array(
            'type' => 'MultiCheckbox',
            'name' => 'hobby',
            'options' => array(
                'label' => 'Hobby',
                'value_options' => array(
                    'go shopping' => 'go shopping',
                    'surf the Internet' => 'surf the Internet',
                    'watch movies' => 'watch movies',
                    'traveling' => 'traveling'
                )
            )
        ));

        $this->add(array( 'name'=>'introduction', 'attributes'=>array( 'type'=>'Text', ), 'options'=>array( 'label'=>'introduction', ), ));

        $this->add(array( 'name'=>'email', 'attributes'=>array( 'type'=>'email', ), 'options'=>array('label'=>'email', ),
                      'attributes'=>array('required'=>'required',), 'filters'=>array(array('name'=>'StringTrim'),),
                      'validators'=>array(array( 'name'=>'EmailAddress', 'options'=>array( 'messages'=>array(
                          \Zend\Validator\EmailAddress::INVALID_FORMAT => 'Email address format is invalid ' ),), )), // 这里添加了缺失的括号
                     ));
        $this->add(array( 'name'=>'password', 'attributes'=>array( 'type'=>'Password',), 'options'=>array( 'label'=>'password', ),));
        // $this->add(array( 'name'=>'confirm_password', 'attributes'=>array('type'=>'Password', ), 'options'=>array('label'=>'confirm_password',),));
        $this->add(array( 'name'=>'submit', 'attributes'=>array('type'=>'Submit', 'value'=>'register', ),  ));
    }
}
?>

